package com.rpframework.core.mybatis.mapper.impl;

import org.apache.ibatis.mapping.MappedStatement;
import tk.mybatis.mapper.mapperhelper.MapperHelper;
import tk.mybatis.mapper.mapperhelper.MapperTemplate;
import tk.mybatis.mapper.mapperhelper.SqlHelper;

/**
 * 查询方法实现类
 * Created by jump on 2016/8/24.
 */
public class SelectProvider extends MapperTemplate {

    public SelectProvider(Class<?> mapperClass, MapperHelper mapperHelper) {
        super(mapperClass, mapperHelper);
    }

    /**
     * 查询值字段
     *
     * @return 值
     */
    public String selectByField(MappedStatement ms) {
        Class<?> entityClass = getEntityClass(ms);
        //修改返回值类型为实体类型
        setResultType(ms, entityClass);
        return "SELECT #{param2}" +
                SqlHelper.fromTable(entityClass, tableName(entityClass)) +
                SqlHelper.whereAllIfColumns(entityClass, isNotEmpty()) +
                SqlHelper.orderByDefault(entityClass);
    }
}
